/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package tletlis.view;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JPanel;
import tletlis.model.*;
/**
 *
 * @author Gustav
 */
public class GamePanel {
    
    private int height;
    private int width;
    private Graphics gamePanelGraphics;
    private Graphics nextBrickPanelGraphics;

    private int nextBrickX;
    private int nextBrickY;
    
    public GamePanel(int width, int height, JPanel panel, JPanel nextBrickPanel) {
         
        this.height = height;
        this.width = width;
        gamePanelGraphics = panel.getGraphics();
        nextBrickPanelGraphics = nextBrickPanel.getGraphics();
        nextBrickX = nextBrickPanel.getSize().width;
        nextBrickY = nextBrickPanel.getSize().height;
    }

    public void gameOver() {
        gamePanelGraphics.setColor(Color.WHITE);
        gamePanelGraphics.fillRect(70, 220, 130, 50);
        gamePanelGraphics.setColor(Color.BLACK);
        gamePanelGraphics.setFont(new Font("hej",Font.BOLD,20));
        gamePanelGraphics.drawString("GAMEOVER", 80, 250);

    }

    public void drawNextBrickPanel(List<Position> posList, Color c) {
        nextBrickPanelGraphics.setColor(Color.BLACK);
        nextBrickPanelGraphics.fillRect(0, 0, nextBrickX, nextBrickY);
        nextBrickPanelGraphics.setColor(c);
        for(Position p: posList) {
            nextBrickPanelGraphics.fillRect(p.getX()-100, p.getY()+25, Position.getLength(), Position.getLength());

        }
    }
    
    public void drawAllGameBoard(RowList rowList) {

       
       for(Row row: rowList.getRowList()) {
            for(GamePosition p: row.getGamePosList() ) {
                drawGameBoard(p,Color.BLACK);
            }
            
            
        }
        
    }
    
    public void drawGameBoard(List<Position> posList, Color c) {
        
        for(Position gp: posList) {
            gamePanelGraphics.setColor(c);
            gamePanelGraphics.fillRect(gp.getX(), gp.getY(), Position.getLength(), Position.getLength());
            
        }
        
    }

    public void removeRow(List<GamePosition> posList, Color c) {

        for(Position p: posList) {
            drawGameBoard(p,c);
        }
    }
    
    public void drawGameBoard(Position gamePos, Color c) {
        gamePanelGraphics.setColor(c);
        gamePanelGraphics.fillRect(gamePos.getX(), gamePos.getY(), Position.getLength(), Position.getLength());
        
    }

    public void win() {
        gamePanelGraphics.setColor(Color.WHITE);
        gamePanelGraphics.fillRect(70, 220, 130, 50);
        gamePanelGraphics.setColor(Color.BLACK);
        gamePanelGraphics.setFont(new Font("hej",Font.BOLD,20));
        gamePanelGraphics.drawString("YOU WIN", 80, 250);
    }
   
        

}
